
Partial Class UReg
    Inherits System.Web.UI.Page
    Dim str As String

    Protected Sub UReg_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("type") <> "" Then
            Response.Redirect("Error.aspx")
            Exit Sub
        End If

        If Me.IsPostBack = False Then
            Dim a As New Globo
            a.executesql("select * from Countries", False)
            While a.dr.Read = True
                ddlCon.Items.Add(a.dr(0))
            End While
            ddlCon.SelectedIndex = 110

            Dim b As New Globo
            b.executesql("select * from domain", False)
            While b.dr.Read = True
                ddlEmail.Items.Add(b.dr(0))
            End While
            b.dr.Close()
        End If
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        'Blank Filed Validation Check
        '++++++++++++++++++++++++++++++++++++++++++
        If txtUEmail.Text = "" Then
            lblErr.Text = "Enter Email ID"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtPswd.Text = "" Then
            lblErr.Text = "Enter Password"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtRePswd.Text = "" Then
            lblErr.Text = "Retype Password"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtUName.Text = "" Then
            lblErr.Text = "Enter Username"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtSecQuest.Text = "" Then
            lblErr.Text = "Enter Security Question"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtAns.Text = "" Then
            lblErr.Text = "Enter the answer"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtFname.Text = "" Then
            lblErr.Text = "Enter First Name"
            lblErr.Visible = True
            Exit Sub
        Else
            str = txtFname.Text
            str = UCase(Left(str, 1)) & LCase(Right(str, str.Length - 1))
            txtFname.Text = str
        End If

        If txtLname.Text = "" Then
            lblErr.Text = "Enter Last Name"
            lblErr.Visible = True
            Exit Sub
        Else
            str = txtLname.Text
            str = UCase(Left(str, 1)) & LCase(Right(str, str.Length - 1))
            txtLname.Text = str
        End If

        If ddlGen.Text = "" Then
            lblErr.Text = "Select Gender"
            lblErr.Visible = True
            Exit Sub
        End If

        If ddlCon.Text = "" Then
            lblErr.Text = "Select Country"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtLoc.Text = "" Then
            lblErr.Text = "Enter Your Location"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtZip.Text = "" Then
            lblErr.Text = "Enter Pin/Zip Code"
            lblErr.Visible = True
            Exit Sub
        End If

        If chkEULA.Checked = False Then
            lblErr.Text = "Plese accept the Terms & Conditions to continue.."
            lblErr.Visible = True
            Exit Sub
        End If


        '++++++++++++++++++++++++++++++++++++++++++
        'password mismatch validation check
        '``````````````````````````````````````````
        If txtPswd.Text <> txtRePswd.Text Then
            lblErr.Text = "Password Mismatch"
            lblErr.Visible = True
            Exit Sub
        End If


        '___________________________________________
        'Numeric validation
        '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        If IsNumeric(txtFname.Text) Then
            lblErr.Text = "Invalid First Name"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtMname.Text <> "" And IsNumeric(txtMname.Text) Then
            lblErr.Text = "Invalid Middle Name"
            lblErr.Visible = True
            Exit Sub
        End If

        If IsNumeric(txtLname.Text) Then
            lblErr.Text = "Invalid Last Name"
            lblErr.Visible = True
            Exit Sub
        End If


        '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        'Duplicate Data Entry Validation
        '#######################################################
        Dim c As New Globo
        c.executesql("select * from users where uemail = '" & txtUEmail.Text & "'", False)
        If c.dr.Read = True Then
            lblErr.Text = "Email Id already Registered"
            lblErr.Visible = True
            c.dr.Close()
            Exit Sub
        End If

        Dim u, b As New Globo
        u.executesql("select * from users where uid = '" & txtUName.Text & "'", False)
        'Dim b As New Globo
        b.executesql("select * from buyers where buyer_id = '" & txtUName.Text & "'", False)
        If u.dr.Read Or b.dr.Read Then
            lblErr.Text = "User ID Unavailable"
            lblErr.Visible = True
            b.dr.Close()
            Exit Sub
        End If


        '#######################################################
        'Data Insertion
        '*******************************************************
        Dim email As String
        email = LCase(txtUEmail.Text & "@" & ddlEmail.Text)

        Dim a As New Globo
        a.executesql("insert into users values ('" & LCase(txtUName.Text) & "', '" & email & "', '" & a.oCrypto.EncryptTripleDES(txtPswd.Text, Globo.sEncryptionKey).Replace("'", "''") & "', '" & txtFname.Text & "', '" & txtMname.Text & "', '" & txtLname.Text & "', '" & ddlGen.Text & "', '" & ddlCon.Text & "', '" & txtLoc.Text & "', '" & txtZip.Text & "', '" & txtSecQuest.Text & "', '" & txtAns.Text & "', '" & txtSecEmail.Text & "')", True)
        MsgBox("New user created." & vbCrLf & "Please login to continue..       ", MsgBoxStyle.OkOnly, "User registration confirmation")

        '*******************************************************
        Server.Transfer("Loading.aspx")
    End Sub

    Protected Sub lnkAboutUs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkAboutUs.Click
        Response.Redirect("AboutUs.aspx")
    End Sub

    Protected Sub lnkTermCond_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkTermCond.Click
        Response.Redirect("TermsConditions.aspx")
    End Sub

    Protected Sub lnkContactUs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkContactUs.Click
        Response.Redirect("ContactUs.aspx")
    End Sub

    Protected Sub lnkFAQs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFAQs.Click
        Response.Redirect("FAQs.aspx")
    End Sub

    Protected Sub lnkFeedback_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFeedback.Click
        Response.Redirect("Feedback.aspx")
    End Sub
End Class